package com.arpa.wms.domain.enums;

import cn.hutool.core.util.StrUtil;
import com.arpa.ntocc.common.common.exception.ServiceException;
import com.arpa.wms.domain.entity.Carrier;

import java.util.HashMap;
import java.util.Map;

/**
 * 承运商类型枚举
 * @author
 */
public enum CarrierTypeEnum {
    /**
     * 快递
     */
    EXPRESS("express","快递"),
    /**
     * 物流
     */
    LOGISTICS("logistics","物流");

    /**
     * 值
     */
    private String value;

    /**
     * 描述
     */
    private String desc;

    CarrierTypeEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return value;
    }


    public String getDesc() {
        return desc;
    }

    public static String translate(String value){
        CarrierTypeEnum item = ENUM_MAP.get(value);
        if(item != null){
            return item.getDesc();
        }
        return StrUtil.EMPTY;
    }

    private static final Map<String, CarrierTypeEnum> ENUM_MAP = new HashMap();

    static {
        for(CarrierTypeEnum item: values()){
            ENUM_MAP.put(item.getValue(), item);
        }
    }


    /**
     * 根据承运商类型枚举，获取校验分组类型
     * @param carrierType
     * @return
     */
    public static Class validateGroupClass(String carrierType) {
        CarrierTypeEnum carrierTypeEnum = ENUM_MAP.get(carrierType);
        if (carrierTypeEnum == null){
            throw new ServiceException("承运商类型错误");
        }
        switch (carrierTypeEnum){
            case EXPRESS:
                return Carrier.Express.class;
            case LOGISTICS:
                return Carrier.Logistics.class;
            default:
                throw new ServiceException("承运商类型错误");
        }
    }

}
